<?php

namespace app\controllers;

use app\models\LoginFormFactory;
use myVendor\Factorys;

class LoginController extends BaseController
{
    public function actionIndex()
    {
        $model = Factorys::getLoginForm();
        if ($model->load(\Yii::$app->request->post()) && $model->login()) {
            return $this->redirect(['admin/param']);
        }
        $userservice=Factorys::getUserService();
        if(!$userservice->checkIsGuest()){
            return $this->redirect(['admin/param']);
        }

        return $this->render('login', [
            'model' => $model,
        ]);
    }

    public function actionLogout(){
        $userservice=Factorys::getUserService();
        $userservice->Logout();
        return $this->redirect(['/login']);
    }
}